home *** CD-ROM | disk | FTP | other *** search
- <?php if (!defined("SOexcel")) { define("SOExcel", 1);
-
- include("SOhttp.php");
-
- // Convert Excel coordinate (e.g., "C6") into numeric X,Y (e.g., 2,5)
- // Inputs:
- // $sCell: cell desigation (e.g., "C6")
- // $nX: X-coordinate (column, e.g., 2) using zero-based counting
- // $nY: Y-coordinate (row, e.g., 5) using zero-based counting
- // Outputs:
- // None
- //
- function SOExcelCell2RowCol($sCell, &$nX, &$nY) {
- $nX = $nY = 0;
- $sCell = strtoupper($sCell);
- $nX = ord($sCell) - 65;
- $sCell = substr($sCell, 1);
- if (ord($sCell) > 64) {
- $nX *= 26;
- $nX += (ord($sCell) - 65);
- $sCell = substr($sCell, 1);
- }
- $nY = $sCell;
- settype($nY, "integer");
- $nY--;
- return ("");
- }
-
- // Retrieve Excel data over specified range and fill in associative
- // array with values.
- // Inputs:
- // $sAddr: address of BadBlue server (e.g., "127.0.0.1:8080")
- // $sPath: path of shared file in EXT.INI file (e.g., "path3")
- // $sFile: name of Excel file to examine (e.g., "invoice.xls")
- // $nSheet: sheet number (e.g., 1)
- // $aData: associative array returned with data
- // $sCellStart: starting cell of area to retrieve (e.g., "A1")
- // $sCellEnd: ending cell of area to retrieve (e.g., "G99")
- // $sUser: (optional) user-name to get access to file
- // $sPassword: (optional) password to get access to file
- // Outputs:
- // $errmsg: empty if no error occurred, otherwise error message
- //
- function SOExcel($sAddr, $sPath, $sFile, $nSheet, &$aData,
- $sCellStart, $sCellEnd, $sUser = "", $sPassword = "") {
- $aData = array();
- $nDX = 25;
- $nDY = 50;
- $errmsg = "";
- do {
-
- // Convert cell addressing to numeric row/columns...
- //
- SOExcelCell2RowCol($sCellStart, $nXS, $nYS);
- SOExcelCell2RowCol($sCellEnd, $nXE, $nYE);
- // echo(" nXS= $nXS nYS= $nYS nXE= $nXE NYE= $nYE <BR>");
-
- // Loop through by chunks until done.
- //
- for ($nY = $nYS; $nY <= $nYE; $nY += $nDY) {
- for ($nX = $nXS; $nX <= $nXE; $nX += $nDX) {
-
- // Construct URL and grab page...
- //
- $sURL = "http://".$sAddr."/ext.dll?MfcISAPICommand=LoadPage&".
- "page=xls.htx&a0=/get/".$sPath."/".rawurlencode($sFile)."&a1=".$nSheet."&a2=_&".
- "a3=".$nX."&a4=".$nY."&a5=".$nDX."&a6=".$nDY."&a7=2&a8=100%25";
- $errmsg = SOHTTPGet($sURL, &$sPage, $sUser, $sPassword);
- if (strlen($errmsg)) {
- break;
- }
- $aColumns = array();
-
- // Rip through first row of matrix to grab column labels.
- //
- for ($i = 0; $i < $nDX + 1; $i++) {
- $sTemp = "<TD class=fXH align=center>";
- $nCursor = strpos($sPage, $sTemp);
- if ($nCursor === false) {
- $errmsg = "Invalid template file (1)";
- break;
- }
- $nCursor += strlen($sTemp);
- if (!$i) {
- $sPage = substr($sPage, $nCursor + 2);
- continue;
- }
- $sColumn = substr($sPage, $nCursor, 2);
- if (($nCursor2 = strpos($sColumn, '<')) > 0) {
- $sColumn = substr($sColumn, 0, $nCursor2);
- }
- $aColumns[$i - 1] = $sColumn;
- $sPage = substr($sPage, $nCursor + 2);
- }
- if (strlen($errmsg)) {
- break;
- }
- // echo("Columns=".implode(", ", $aColumns)."<BR>");
-
- // Rip through multiple rows of data...
- //
- for ($i = 0; $i < $nDY; $i++) {
- for ($j = 0; $j < $nDX; $j++) {
- $sTemp = "<TD class=fXL";
- $nCursor = strpos($sPage, $sTemp);
- if ($nCursor === false) {
- $errmsg = "Invalid template file (2)";
- break;
- }
- $nCursor += strlen($sTemp);
- $nCursor = strpos($sPage, ">", $nCursor);
- if ($nCursor === false) {
- $errmsg = "Invalid template file (3)";
- break;
- }
- $nCursor++;
- //
- $sVal = substr($sPage, $nCursor, 255);
- if (($nCursor2 = strpos($sVal, '<')) > 0) {
- $sVal = substr($sVal, 0, $nCursor2);
- }
- //
- $sPage = substr($sPage, $nCursor + $nCursor2);
- $nTemp = $nY + $i + 1;
- settype($nTemp, "string");
- $aData[$aColumns[$j].$nTemp] = $sVal;
- // echo("Cell ".$aColumns[$j].$nTemp."= ".$sVal."<BR>");
- }
- if (strlen($errmsg)) {
- break;
- }
- }
- // ...end loop through chunks.
- //
- }
- if (strlen($errmsg)) {
- break;
- }
- }
-
- } while (0);
- return ($errmsg);
- }
-
- } ?>
-